Only call value method if it has zero arity #496
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a compatibility problem with Rails when the user specifies
parameter
with the same name asActionDispatch::Integration::RequestHelpers
methods.This came up in our application because we are accepting a parameter name
options
, and when upgrading to Rails 6.1 we starting to get this error:After some investigation, it seems like Rails 6.1 has added
options
method toActionDispatch::Integration::RequestHelpers
which get included to Request specs:https://github.com/rails/rails/blob/v6.1.1/actionpack/lib/action_dispatch/testing/integration.rb#L49-L53
Therefore when rspec_api_documentation tries to call
options
method to get the value, it accidentally calling this helper method from Rails instead and resulting inArgumentError
.Since it's a bit tricky to detect where the method was defined, I propose a solution in this PR in which we just check if the value method has an arity of zero (i.e. doesn't take any argument) before calling it. This way,
rspec_api_documentation
will still automatically call a value method if it's defined or overridden by the user.